package cn.me.alphamq.vo;

import cn.me.alphamq.common.model.broker.CommitLogFileModel;
import cn.me.alphamq.common.model.broker.CommitLogTopicModel;

import java.time.Instant;

import static cn.me.alphamq.constant.ConsoleConstant.DATE_TIME_FORMATTER;

/**
 * topic 信息的视图对象
 *
 * @author f
 */
public class TopicInfoVO {

    /**
     * topic 的名称
     */
    private String topic;

    /**
     * 队列数
     */
    private Integer queueSize;

    /**
     * 偏移量
     */
    private Integer offset;

    /**
     * 偏移量的最大值
     */
    private Integer offsetLimit;

    /**
     * 创建时间
     */
    private String createTime;

    /**
     * 修改时间
     */
    private String updateTime;

    public TopicInfoVO() {
    }

    public TopicInfoVO(CommitLogTopicModel commitLogTopicModel) {
        this.topic = commitLogTopicModel.getTopic();
        this.queueSize = commitLogTopicModel.getQueueList().size();
        this.createTime = DATE_TIME_FORMATTER.format(Instant.ofEpochMilli(commitLogTopicModel.getCreateAt()));
        this.updateTime = DATE_TIME_FORMATTER.format(Instant.ofEpochMilli(commitLogTopicModel.getUpdateAt()));
        CommitLogFileModel commitLogFileModel = commitLogTopicModel.getCommitLogFileModel();
        this.offset = commitLogFileModel.getOffset().get();
        this.offsetLimit = commitLogFileModel.getOffsetLimit();
    }

    public String getTopic() {
        return topic;
    }

    public void setTopic(String topic) {
        this.topic = topic;
    }

    public Integer getQueueSize() {
        return queueSize;
    }

    public void setQueueSize(Integer queueSize) {
        this.queueSize = queueSize;
    }

    public Integer getOffset() {
        return offset;
    }

    public void setOffset(Integer offset) {
        this.offset = offset;
    }

    public Integer getOffsetLimit() {
        return offsetLimit;
    }

    public void setOffsetLimit(Integer offsetLimit) {
        this.offsetLimit = offsetLimit;
    }

    public String getCreateTime() {
        return createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    public String getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(String updateTime) {
        this.updateTime = updateTime;
    }
}
